**********************************************************************************************************
* Do-file to replicate analyses in 'Clientelism, party organization and intra-party democracy'
* February 2024
**********************************************************************************************************

*+++++++++++++++++++++++++++++++PREAMBLE+++++++++++++++++++++++++++++++++++++* 

cd "" // Set path to directory where replication package was unzipped

*******************
* ADOs
*******************
*ssc install estout, replace 


*-------------------------------------------------------------------------------
* ANALYSES IN THE MAIN TEXT
*-------------------------------------------------------------------------------
use "V-Dem-CPD-Party-V2.dta"
gen Communist_successor=.
replace Communist_successor=1 if pf_party==57 | pf_party==64 & year>2000 | pf_party==546 | pf_party==588 |	pf_party==600 | pf_party==741 | pf_party==757 | pf_party==1150 | pf_party==1242 | pf_party==1347 | pf_party==1403 | pf_party==1408 | pf_party==1475 | pf_party==1665 | pf_party==1728 | pf_party==4002 | pf_party==	7238 | pf_party==120 |	pf_party==311 |	pf_party==602 |	pf_party==757 |	pf_party==1242 | pf_party==1347 | pf_party==1408	| pf_party==1665 |	pf_party==1728 | pf_party==2030	| pf_party==2220 | pf_party==2236 | pf_party==2260 | pf_party==4002 | pf_party==6985
recode Communist_successor (.=0)
keep if e_regionpol_6C==1 & e_regiongeo!=11 & year>1989
drop if country_name=="Mongolia" | country_name=="Armenia" | country_name=="Azerbaijan" | country_name=="German Democratic Republic" | country_name=="Kosovo" | country_name=="Belarus" | country_name=="Georgia"
replace v2paind=-1*(v2paind)
gen intra_party=(v2panom+v2paind)/2
drop  *_osp *_ord *_codelow *_codehigh *_sd *_mean
gen EU=0 if year<2004
recode EU (.=1) if year>2003 & country_name=="Czech Republic" | country_name=="Estonia" | country_name=="Hungary" | country_name=="Latvia" | country_name=="Lithuania" | country_name=="Poland" | country_name=="Slovakia"
recode EU (.=1) if year>2006 & country_name=="Bulgaria" | country_name=="Romania"
recode EU (.=1) if year>2012 & country_name=="Croatia"
recode EU (.=0)
gen EU_MS=1 if country_name=="Czech Republic" | country_name=="Estonia" | country_name=="Hungary" | country_name=="Latvia" | country_name=="Lithuania" | country_name=="Poland" | country_name=="Slovakia" | country_name=="Bulgaria" | country_name=="Romania" | country_name=="Croatia"
recode EU_MS (.=0)
recode EU (0=1) if year>2003 & country_name=="Slovenia"
recode EU_MS (0=1) if country_name=="Slovenia"
save "V-Dem-CPD-Party-V2_EE_post89.dta"

*Table 1: Clientelism and intra-party democracy in CEE
keep if EU_MS==1
bysort year country_name :gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
foreach var in intra_party v2paclient v2xpa_popul v2pariglef v2paseatshare extremism {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3, cluster(v2paid)
estimates store m1, title(Model 1)
xtset v2paid year
xtreg intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.year if EU_MS==1 & v2paclient_nr>3  & v2panom_nr>3 & v2paind_nr>3, fe
estimates store m2, title(Model 2)
estout m*, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)

*Figure 1: Substantive effect of clientelism
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3, cluster(v2paid)
generate where = 0 if v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3
generate pipe = "|" if v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3, cluster(v2paid)
margins, at(v2paclient =(0(.2)1)) atmeans
marginsplot, level(95) recast(line) recastci(rline) name(graph1, replace) addplot (scatter where v2paclient if v2paclient!=., ms(none) mlabel(pipe) mlabpos(0)) legend(off) yscale(range(0(.2) 1)) ytitle("Predicted values of intra-party democracy") scheme(plotplain) aspectratio(1)

*Table 2: Clientelism and intra-party democracy: broader sample without CEE parties 
clear all
use "V-Dem-CPD-Party-V2.dta"
keep if year>1989
merge m:1 country_id year using "regime type VDEM.dta"
drop if _merge==2
keep if v2x_regime>1
bysort year country_name :gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
replace v2paind=-1*(v2paind)
gen intra_party=(v2panom+v2paind)/2
foreach var in  intra_party v2paclient v2xpa_popul v2pariglef v2paseatshare extremism {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
gen EU_MS=1 if country_name=="Czech Republic" | country_name=="Estonia" | country_name=="Hungary" | country_name=="Latvia" | country_name=="Lithuania" | country_name=="Poland" | country_name=="Slovakia" | country_name=="Bulgaria" | country_name=="Romania" | country_name=="Croatia" |country_name=="Slovenia"
regress intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.country_id i.year if v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & EU_MS!=1, cluster(v2paid)
estimates store m1, title(Model 5)
xtset v2paid year
xtreg intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.year if v2paclient_nr>3  & v2panom_nr>3 & v2paind_nr>3 & EU_MS!=1, fe
estimates store m2, title(Model 6)
estout m1 m2, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)

*Table 3: Clientelism and intra-party democracy – electoral vs liberal democracies 
regress intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.country_id i.year if v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 &v2x_regime==2, cluster(v2paid)
estimates store m3, title(Model 3)
regress intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.country_id i.year if v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 &v2x_regime==3, cluster(v2paid)
estimates store m4, title(Model 4)
xtset v2paid year
xtreg intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.year if v2paclient_nr>3  & v2panom_nr>3 & v2paind_nr>3 &v2x_regime==2, fe
estimates store m5, title(Model 5)
xtreg intra_party v2paclient v2pariglef extremism v2xpa_popul v2paseatshare i.year if v2paclient_nr>3  & v2panom_nr>3 & v2paind_nr>3 &v2x_regime==3, fe
estimates store m6, title(Model 6)
estout m3 m4 m5 m6, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)

*-------------------------------------------------------------------------------
* ADDITIONAL ANALYSES IN THE APPENDIX
*-------------------------------------------------------------------------------

*Table A1: Descriptive statistics
clear all
use "V-Dem-CPD-Party-V2_EE_post89.dta"
keep if EU_MS==1
bysort year country_name :gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
foreach var in intra_party v2paclient v2xpa_popul v2pariglef v2paseatshare extremism {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3, cluster(v2paid)
local vars intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare
sum `vars' if e(sample)==1

*Table A2: Correlation matrix of variables
pwcorr `vars' if e(sample)==1, star(.05)
estpost correlate `vars' if e(sample)==1, matrix
esttab ., not unstack compress noobs star(* 0.05 ** 0.01 *** 0.001) b(%8.2f)


*Table A3: Clientelism and the POPPA measure of intra-party democracy
clear all
use "V-Dem-CPD-Party-V2_EE_post89.dta"
keep if EU_MS==1
bysort year country_name :gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
merge m:1 pf_party_id using "POPPA data.dta"
keep if _merge==3
bysort v2paid (year): gen dup=_n
bysort v2paid (year): egen max_dup=max(dup)
keep if dup==max_dup
foreach var in intradem v2paclient v2xpa_popul v2pariglef v2paseatshare extremism  {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
regress intradem v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id, robust
estout, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)


*Table A4: Varieties of clientelism and intra-party democracy (DALP data)
clear all
use "V-Dem-CPD-Party-V2_EE_post89.dta"
keep if EU_MS==1
bysort year country_name :gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
merge m:1 pf_party_id using "DALP data.dta"
keep if _merge==3
gen time_close=abs(year-year_last)
bysort v2paid: egen closest=min(time_c)
keep if closest==time
foreach var in b15 relational_client b1 intra_party v2paclient v2xpa_popul v2pariglef v2paseatshare extremism  {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
regress intra_party b15 v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id, robust
estimates store m1
regress intra_party relational_client v2pariglef extremism Communist_successo v2xpa_popul  v2paseatshare i.country_id, robust
estimates store m2
regress intra_party b1 v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id, robust
estimates store m3
estout m*, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)

*Table A5: Clientelism and intra-party democracy (models dropping one country from the sample at a time)
clear all
use "V-Dem-CPD-Party-V2_EE_post89.dta"
keep if EU_MS==1
bysort year country_name: gen weighed_LR= (v2pariglef*v2paseatshare/100)
bysort year country_name: egen centre_LR =mean(weighed_LR)
bysort year country_name: gen extremism =abs(weighed_LR-centre_LR)
foreach var in  intra_party v2paclient v2xpa_popul v2pariglef v2paseatshare extremism {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=17, cluster(v2paid)
estimates store m1, title(Model 1)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=152, cluster(v2paid)
estimates store m2, title(Model 2)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=154, cluster(v2paid)
estimates store m3, title(Model 3)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=157, cluster(v2paid)
estimates store m4, title(Model 4)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=161, cluster(v2paid)
estimates store m5, title(Model 5)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=173, cluster(v2paid)
estimates store m6, title(Model 6)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=190, cluster(v2paid)
estimates store m7, title(Model 7)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=201, cluster(v2paid)
estimates store m8, title(Model 8)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=202, cluster(v2paid)
estimates store m9, title(Model 9)
regress intra_party v2paclient v2pariglef extremism Communist_successo v2xpa_popul v2paseatshare i.country_id  i.year if EU_MS==1 & v2panom_nr>3 & v2paind_nr>3 & v2paclient_nr>3 & country_id!=210, cluster(v2paid)
estimates store m10, title(Model 10)
estout m1 m2 m3 m4 m5, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)
estout m6 m7 m8 m9 m10, cells(b(star fmt(%9.2f)) se(par)) starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 N)


